<?php
	include_once("inc/conn.php");
    include_once("inc/function.php");
    
    if(!isset($_SESSION['usersid'])) {
		echo "您还没登录或者链接超时，请先去<a href='/login.php'>登录</a>!";
		exit;
	}
	RefreshPoints();
	$act = intval($_GET['act']);
	//返回投注界面
	GetGamePressContent($act);
	
    /* 取得下注界面
    * 
    */
    function GetGamePressContent($act)
    {
		$sid = intval($_GET['sid']);
		$No = intval($_GET['no']);
		$LastNo = $No - 1;
		$arrCurNoInfo = array('preno'=>'','prekgtime'=>'','game_kj_delay'=>'','game_tz_close'=>'');
		
		if($No == 0)
		{
			echo "非法提交数据!";
			exit;
		}
		
		$RetContent = "<div class='criterion'>\r\n";
		$RetContent .= "\t<div class='Content'>\r\n";
		//取得子菜单
		//$RetContent .= GetSubMenu($act,$sid);
		//取得开奖头
		$RetContent .= get_yj_head_content($act,$sid,$arrCurNoInfo);
		//投注按钮
		$RetContent .= GetButtonContent($act);
		//取押注倍数
		$RetContent .= GetTimesContent($act,$No,$LastNo);
		$RetContent .= "\t</div>\r\n"; //content结束
		//取号码表格
		$RetContent .= GetTableContent($act,$No,$LastNo);
		
		$RetContent .= "</div>\r\n";
		//js 定义
		$RetContent .= GetJSContent($act,$No);
		$RetContent .= GetRewardJS($act,$arrCurNoInfo,"head"); 
		$RetContent .= "<script type='text/javascript' src='js/game28.js'>\r\n";
		echo $RetContent;
		exit;
    }
    
    /* 取得押注按钮定义
    *
    */
    function GetButtonContent($act)
    {
    	global $db;
		$tableautotz = GetGameTableName($act,"auto_tz");
		$sql = "SELECT id,tzname FROM {$tableautotz} WHERE uid = '{$_SESSION['usersid']}'";
		$result = $db->query($sql);
		$ModelList = "我的投注模式: ";
		while($rs = $db->fetch_array($result))
		{
			$ModelList .= "<a href=\"javascript:getpressinfo({$rs['id']},'id')\">". ChangeEncodeG2U($rs['tzname']) ."</a>  ";
		}
		$ModelList .= " <a href=\"javascript:getContent('smodel.php?act={$act}&sid=4')\">模式编辑</a>";
		//投注按钮
		if(!in_array($act,array(11,12,13,21,16))) {
			$divMode = "<div class='mode'>\r\n";
			$divMode .= "\t<p>{$ModelList}</p>\r\n";
			$divMode .= "\t<ul>\r\n";
			
			/* wk 新增  玩法规则 start */
			$divMode .= "\t\t<li><a onclick='javascript:useModel(1,this)'>大</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(2,this)'>小</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(3,this)' >单</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(4,this)'>双</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(5,this)'>大单</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(6,this)'>小单</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(7,this)'>大双</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(8,this)'>小双</a></li>\r\n"; 
			$divMode .= "\t\t<li><a onclick='javascript:useModel(9,this)'>顺子</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(10,this)'>对子</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(11,this)'>豹子</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(12,this)'>龙</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(13,this)'>虎</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(14,this)'>豹</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(15,this)'>极大</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(16,this)'>极小</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(17,this)'>任意数字</a></li>\r\n";
			$divMode .= "\t\t<li  style=\"display:none;\"><input type=\"number\" id=\"numbers\" style=\"width: 100%;\" onchange=\"wk_numbers(); \"  ></li>\r\n";
		
		
			/* wk 新增  玩法规则 end */ 
			
			/*  wk  注释之前的 玩法
			$divMode .= "\t\t<li><a onclick='javascript:useModel(2)' >单</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(1)'>双</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(4)'>大</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(3)'>小</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(5)'>中</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(6)'>边</a></li>\r\n";

			$divMode .= "\t\t<li><a onclick='javascript:useModel(7)'>大单</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(8)'>小单</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(9)'>大双</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(10)'>小双</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(11)'>大边</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(12)'>小边</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(13)'>0尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(14)'>1尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(15)'>2尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(16)'>3尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(17)'>4尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(18)'>小尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(19)'>5尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(20)'>6尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(21)'>7尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(22)'>8尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(23)'>9尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(24)'>大尾</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(25)'>3余0</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(26)'>3余1</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(27)'>3余2</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(28)'>4余0</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(29)'>4余1</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(30)'>4余2</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(31)'>4余3</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(32)'>5余0</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(33)'>5余1</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(34)'>5余2</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(35)'>5余3</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:useModel(36)'>5余4</a></li>\r\n";
			$divMode .= "\t</ul>\r\n";

			$divMode .= "\t<ul>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(0.1)'>0.1倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(0.5)'>0.5倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(0.8)'>0.8倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(1.2)'>1.2倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(1.5)'>1.5倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(2)'>2倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(5)'>5倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(10)'>10倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(50)'>50倍</a></li>\r\n";
			$divMode .= "\t\t<li><a onclick='javascript:chgAllTimes(100)'>100倍</a></li>\r\n";
			*/
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			$divMode .= "\t</ul>\r\n";
			$divMode .= "</div>\r\n";
		}
		return $divMode;
    }
    
    /* 取押注倍数
    *
    */
    function GetTimesContent($act,$No,$LastNo)
    {
		//倍数
		$divTimes = "<div class='times'>\r\n";
		$divTimes .= "\t<input type='hidden' id='hidTimes' value='1' />\r\n"; 
		$divTimes .= "\t<ul class='power'>\r\n";
		$divTimes .= "\t\t<li><a class='chips1' onclick='javascript:chips(10,1)'><img src=\"image/chips_10000.png\" alt=\"1000\" /></a></li>\r\n";
		$divTimes .= "\t\t<li><a class='chips2' onclick='javascript:chips(100,2)'><img src=\"image/chips_100000.png\" alt=\"1000\" /></a></li>\r\n";
		$divTimes .= "\t\t<li><a class='chips3' onclick='javascript:chips(500,3)'><img src=\"image/chips_500000.png\" alt=\"1000\" /></a></li>\r\n";
		$divTimes .= "\t\t<li><a class='chips4' onclick='javascript:chips(1000,4)'><img src=\"image/chips_1000000.png\" alt=\"1000\" /></a></li>\r\n";
		$divTimes .= "\t\t<li><a class='chips5' onclick='javascript:chips(5000,5)'><img src=\"image/chips_5000000.png\" alt=\"1000\" /></a></li>\r\n";
		$divTimes .= "\t</ul>\r\n";

		/*$divTimes.='<script type="text/javascript">$(function() {
  $(".power a").click(function() {
    $(".power a").removeClass("active");
    $(this).addClass("active");
  });
})</script>';*/
		
		
		
		$divTimes .= "\t<ul class='self input-group'>\r\n";
		/*  wk  新增 <inptu type=\"hidden\" id=\"wk_type\" >  记录选择的类型  在开奖的时候发放  */
		
		$divTimes .= "\t\t<li><input type=\"text\" class=\"form-control wk-form-control \" onchange=\" wk_ledou(); \" placeholder=\"请输入宝币\" id=\"betsLeft\"><input type=\"hidden\" id=\"wk_type\" > </li> \r\n";
		// $divTimes .= "\t\t<a onclick=\"javascript:usefenpei()\" class=\"input-group-addon\">定额梭哈</a></li>\r\n";
		$divTimes .= "\t</ul>\r\n";
		
		$divTimes .= "\t<ul class='depressed' style=\"display:none;\">\r\n";
		$divTimes .= "\t\t<li><a onclick='javascript:RefreshOdds({$act},{$No})'>刷新赔率</a></li>\r\n";
		$divTimes .= "\t\t<li><a onclick='javascript:LastPress({$act},{$LastNo})'>上次投注</a></li>\r\n";
		$divTimes .= "\t\t<li><a onclick='javascript:useModel(0)'>全包</a></li>\r\n";
		$divTimes .= "\t\t<li><a onclick='javascript:useSuoha()'>梭哈</a></li>\r\n";
		$divTimes .= "\t\t<li><a onclick='javascript:subSelect()'>反选</a></li>\r\n";
		$divTimes .= "\t\t<li class='not'><a href='javascript:init()'>清除</a></li>\r\n";
		$divTimes .= "\t</ul>\r\n";
						
		$divTimes .= "\t<ul class='total' style=\"float: right;\">\r\n";
		$divTimes .= "\t\t<li class='t'>\r\n";
		$divTimes .= "总投注宝币:<i id='tbTotal'>0</i>";
		$divTimes .= "\t\t</li>\r\n";
		$divTimes .= "\t\t<li><a onclick='javascript:ToSave({$act},{$No})' class=\"btn btn-info\">确认投注</a></li>\r\n";
		$divTimes .= "\t</ul>\r\n";

		
		$divTimes .= "</div>";
		return $divTimes;
    }
    
    /* 取号码表格
    *
    */
    function GetTableContent($act,$No,$LastNo)
    {
    	global $db;
    	$tablegame = GetGameTableName($act,"game");
    	$tablegamekg = GetGameTableName($act,"kg_users_tz");
		//号码表格
		//取赔率
		$sql = "select zjpl from {$tablegame} where id in({$No},{$LastNo}) order by id";
		$result = $db->query($sql);
		$curOdds = "";
		$lastOdds = $curOdds;
		if($rs = $db->fetch_array($result))
		{
			 $lastOdds = ($rs['zjpl'] == null) ? $lastOdds : $rs['zjpl'];
			 if($rs = $db->fetch_array($result))
			 {
				 $curOdds = ($rs['zjpl'] == null) ? $curOdds : $rs['zjpl'];
			 }
		}
		$arrCurOdds = explode('|',$curOdds);
		$arrLastOdds = explode('|',$lastOdds);
		//WriteLog($curOdds);
		//取已投注
		$arrHadPress = array();
		$step = GetFromBeginNumStep($act);
		for($i = 0; $i < count($arrCurOdds); $i++)
		{
			$arrHadPress[] = 0;
		}
		$sql = "select tznum,tzpoints from {$tablegamekg} where `NO` = {$No} and uid = {$_SESSION['usersid']}";
		$result = $db->query($sql);
		while($rs=$db->fetch_array($result))
		{
			$arrHadPress[$rs['tznum']-$step] = $rs['tzpoints'];
		}
		//
		$trContent1 = "";
		$trContent2 = "";
		
		for($i = 0; $i < count($arrCurOdds); $i++)
		{
			$RewardNum = $i + $step;
				
			if($i < count($arrCurOdds)/2)
			{     
				$trContent1 .= "\t\t\t<tr>\r\n";
				if($act == 16) //pk龙虎
				{
					$trContent1 .= "\t\t\t\t<td class='number'>龙</td>\r\n";
				}
				else if($act == 11 || $act == 12 || $act == 13 || $act == 21)
				{
					$NumberNameStr = "";
					switch($RewardNum)
					{
						case 1:
							$NumberNameStr = "豹";
							break;
						case 2:
							$NumberNameStr = "对";
							break;
						case 3:
							$NumberNameStr = "顺";
							break;
						case 4:
							$NumberNameStr = "半";
							break;
						case 5:
							$NumberNameStr = "杂";
							break;
						default:
							break;
					}
					$trContent1 .= "\t\t\t\t<td class='number'>{$NumberNameStr}</td>\r\n";
				}
				else
				{
					$trContent1 .= "\t\t\t\t<td class='number number_{$RewardNum}'></td>\r\n";
				}
				$trContent1 .= "\t\t\t\t<td>{$arrLastOdds[$i]}</td>\r\n";
				$trContent1 .= "\t\t\t\t<td><i id='odds_{$i}' >{$arrCurOdds[$i]}</i></td>\r\n";
				$trContent1 .= "\t\t\t\t<td>{$arrHadPress[$i]}</td>\r\n";
				$trContent1 .= "\t\t\t\t<td><input id='tbChk{$i}' type='checkbox' name='tbChk' onclick=\"insert(this,'tbNum{$i}')\"></td>\r\n";
				$trContent1 .= "\t\t\t\t<td><input id='tbNum{$i}' type='text' style='width:60px;' value='' name='tbNum[]' onBlur=\"input(this,'tbChk{$i}')\"  onafterpaste=\"this.value=this.value.replace(/\D/g,'')\" onkeyup=\"this.value=this.value.replace(/\D/g,'')\"></td>\r\n";
				$trContent1 .= "\t\t\t\t<td><a class='multiple' href=\"javascript:chgTimes('tbNum{$i}',0.5)\">.5</a>
				                          <a class='multiple' href=\"javascript:chgTimes('tbNum{$i}',2)\">2</a>
				                          <a class='multiple' href=\"javascript:chgTimes('tbNum{$i}',10)\">10</a>
							 </td>\r\n";
				$trContent1 .= "\t\t\t</tr>\r\n";
			}
			else
			{
				$trContent2 .= "\t\t\t<tr>\r\n";
				if($act == 16) //pk龙虎
				{
				    $trContent2 .= "\t\t\t\t<td class='number'>虎</td>\r\n";
				}
				else if($act == 11 || $act == 12 || $act == 13 || $act == 21)
				{
					$NumberNameStr = "";
					switch($RewardNum)
					{
						case 1:
							$NumberNameStr = "豹";
							break;
						case 2:
							$NumberNameStr = "对";
							break;
						case 3:
							$NumberNameStr = "顺";
							break;
						case 4:
							$NumberNameStr = "半";
							break;
						case 5:
							$NumberNameStr = "杂";
							break;
						default:
							break;
					}
					$trContent2 .= "\t\t\t\t<td class='number'>{$NumberNameStr}</td>\r\n";
				}
				else
				{
					$trContent2 .= "\t\t\t\t<td class='number number_{$RewardNum}'></td>\r\n";
				}
				$trContent2 .= "\t\t\t\t<td>{$arrLastOdds[$i]}</td>\r\n";
				$trContent2 .= "\t\t\t\t<td><i id='odds_{$i}' >{$arrCurOdds[$i]}</i></td>\r\n";
				$trContent2 .= "\t\t\t\t<td>{$arrHadPress[$i]}</td>\r\n";
				$trContent2 .= "\t\t\t\t<td><input id='tbChk{$i}' type='checkbox' name='tbChk' onclick=\"insert(this,'tbNum{$i}')\"></td>\r\n";
				$trContent2 .= "\t\t\t\t<td><input id='tbNum{$i}' type='text' style='width:60px;' value='' name='tbNum[]' onBlur=\"input(this,'tbChk{$i}')\"  onafterpaste=\"this.value=this.value.replace(/\D/g,'')\" onkeyup=\"this.value=this.value.replace(/\D/g,'')\"></td>\r\n";
				$trContent2 .= "\t\t\t\t<td><a class='multiple' href=\"javascript:chgTimes('tbNum{$i}',0.5)\">.5</a>
				                          <a class='multiple' href=\"javascript:chgTimes('tbNum{$i}',2)\">2</a>
				                          <a class='multiple' href=\"javascript:chgTimes('tbNum{$i}',10)\">10</a>
							 </td>\r\n";
				$trContent2 .= "\t\t\t</tr>\r\n";
			}
		}
		$divTable = "<div class='table' style='display:none;'>\r\n";
		$divTable .= "\t<table class='table_list table table-striped table-bordered table-hover' cellspacing='0px' style='border-collapse:collapse;'>\r\n";
		$divTable .= "\t\t<tbody>\r\n";
		$divTable .= "\t\t\t<tr>\r\n";
		$divTable .= "\t\t\t\t<th width='50'>号码</th>\r\n";
		$divTable .= "\t\t\t\t<th width='70'>上期赔率</th>\r\n";
		$divTable .= "\t\t\t\t<th width='70'>当前赔率</th>\r\n";
		$divTable .= "\t\t\t\t<th width='60'>已投注</th>\r\n";
		$divTable .= "\t\t\t\t<th width='40'>选择</th>\r\n";
		$divTable .= "\t\t\t\t<th>投注</th>\r\n";
		$divTable .= "\t\t\t\t<th>倍数</th>\r\n";
		$divTable .= "\t\t\t</tr>\r\n";
		//1 tr
		$divTable .= $trContent1;
		$divTable .= "\t\t</tbody>\r\n";
		$divTable .= "\t</table>";
		
		$divTable .= "\t<table class='table_list table table-striped table-bordered table-hover' cellspacing='0px' style='border-collapse:collapse;'>\r\n";
		$divTable .= "\t\t<tbody>\r\n";
		$divTable .= "\t\t\t<tr>\r\n";
		$divTable .= "\t\t\t\t<th width='50'>号码</th>\r\n";
		$divTable .= "\t\t\t\t<th width='70'>上期赔率</th>\r\n";
		$divTable .= "\t\t\t\t<th width='70'>当前赔率</th>\r\n";
		$divTable .= "\t\t\t\t<th width='60'>已投注</th>\r\n";
		$divTable .= "\t\t\t\t<th width='40'>选择</th>\r\n";
		$divTable .= "\t\t\t\t<th>投注</th>\r\n";
		$divTable .= "\t\t\t\t<th>倍数</th>\r\n";
		$divTable .= "\t\t\t</tr>\r\n";
		//2 tr
		$divTable .= $trContent2;
		
		$divTable .= "\t\t</tbody>\r\n";
		$divTable .= "\t</table>\r\n";
		$divTable .= "</div>\r\n";
		
		return $divTable;
    }
    
    /* 取得JS
    * 
    */
    function GetJSContent($act,$no)
    {
    	global $db;
    	$sql = "select game_table_prefix,game_press_min,game_press_max,game_std_press from game_config where game_type = '{$act}'";
    	$result = $db->query($sql);
    	if($rs = $db->fetch_array($result))
    	{
			$gameType = count(explode(',',$rs['game_std_press']));
			$pressNum = $rs['game_std_press'];
			$press_min = $rs['game_press_min'];
			$press_max = $rs['game_press_max'];
			$sql='select SUM(tzpoints) as points from '.$rs['game_table_prefix'].'_kg_users_tz where NO='.$no.' and uid='.$_SESSION['usersid'];
			$res = $db->query($sql);
			if($row = $db->fetch_array($res))
			{
				$press_max-=$row['points'];

			}
    	}

		$js = "<script type=\"text/javascript\">";
		$js .= "
			var MAX_SCORE = {$press_max};
			var MIN_SCORE = {$press_min};
			var MY_SCORE = {$_SESSION['points']};
			var GTYPE = {$gameType};
			var PRESSNUM = '{$pressNum}';
			var game_id='{$act}';
			
			function getpressinfo(id,ftype)
			{
				$.post('sgameservice.php',{act:'getmodelpress',gtype:{$act},id:id,ftype:ftype},function(ret){
			   		switch(ret.cmd)
			   		{
			   			case 'ok':
			   				init();
			   				setPressInfo(ret.msg);
			   				break;
			   			default:
			   				break;
			   		}
			   },'json');
			}
			function setPressInfo(info)
			{
				var tmpTotal = 0;
			   	var arrPress = info.split(',');
			   	for(var i = 0; i < arrPress.length; i++)
			   	{
			   		if(parseInt(arrPress[i]) > 0)
			   		{
			   			$('#tbChk' + i).attr('checked',true);
	    				$('#tbNum' + i).val(arrPress[i]);
	    				tmpTotal += parseInt(arrPress[i]);
			   		}	
			   	}
			   	$('#tbTotal').html(tmpTotal);
			}
		";
		
		$js .= "</script>\r\n";
		return $js;
    }
